#!/bin/bash
#

listen_number=0
established_number=0

while read line; do
   state=$(echo $line | awk '{print $6}')
   if [ "$state" == "LISTEN" ]; then
	let listen_number++
   elif [ "$state" == "ESTABLISHED" ]; then
	let established_number++
   fi
done < <(netstat -antp | sed '1,2d')

echo "LISTEN状态数：$listen_number, ESTABLISHED状态数：$established_number"
